package cn.wolfcode.filter;

import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@Component
public class TokenFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //传递雇来的参数
        String token=exchange.getRequest().getQueryParams().getFirst("token");
        //token判断
        if (StringUtils.isEmpty(token)){
            exchange.getResponse().setRawStatusCode(HttpStatus.SC_UNAUTHORIZED);
            System.out.println("没有权限");
            return exchange.getResponse().setComplete();
        }
        //token 方行
        return chain.filter(exchange);
    }
}
